package com.starinside.wp;

import com.starinside.wp.interceptor.ActionLogInterceptor;
import com.starinside.wp.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.servlet.MultipartConfigElement;




@SpringBootApplication(scanBasePackages = {"com.starinside", "com.tuo51", "com.matt", "com.dotflat"}, exclude = {ThymeleafAutoConfiguration.class})
@EnableJpaRepositories(basePackages = {"com.starinside", "com.tuo51", "com.matt", "com.dotflat"})
@EntityScan(basePackages = {"com.starinside", "com.tuo51", "com.matt", "com.dotflat"})

public class WpApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
        SpringApplication.run(WpApplication.class, args);
    }

    @Autowired
    AuthInterceptor authInterceptor;

    @Autowired
    ActionLogInterceptor logInterceptor;

    // 增加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor);
        registry.addInterceptor(logInterceptor);
    }

    //上传文件大小设置
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //单个文件最大
        factory.setMaxFileSize("10MB"); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize("10MB");
        return factory.createMultipartConfig();
    }

}
